namespace Guan.CMS.Data.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class InitialCreate : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.SiteConfig",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        SiteName = c.String(maxLength: 100),
                        Footer = c.String(maxLength: 1024),
                        StatisticsCode = c.String(maxLength: 1024),
                        MetaKeywords = c.String(maxLength: 1024),
                        MetaDescription = c.String(maxLength: 2048),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Product",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 500),
                        ImageUrl = c.String(),
                        ShortDescription = c.String(maxLength: 1024),
                        FullDescription = c.String(),
                        IsRecommend = c.Boolean(nullable: false),
                        CreatedTime = c.DateTime(),
                        UpdatedTime = c.DateTime(),
                        IsPublished = c.Boolean(nullable: false),
                        IsDeleted = c.Boolean(nullable: false),
                        Category_Id = c.Int(),
                        SEO_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.ProductCategory", t => t.Category_Id)
                .ForeignKey("dbo.SEOInfo", t => t.SEO_Id)
                .Index(t => t.Category_Id)
                .Index(t => t.SEO_Id);
            
            CreateTable(
                "dbo.ProductCategory",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 100),
                        ParentId = c.Int(),
                        IsPublished = c.Boolean(nullable: false),
                        IsDeleted = c.Boolean(nullable: false),
                        SEO_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.SEOInfo", t => t.SEO_Id)
                .Index(t => t.SEO_Id);
            
            CreateTable(
                "dbo.SEOInfo",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Keywords = c.String(maxLength: 500),
                        Description = c.String(maxLength: 1024),
                        Title = c.String(maxLength: 500),
                        FriendlyName = c.String(maxLength: 1024),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Suppliers",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        CompanyName = c.String(nullable: false, maxLength: 200),
                        CompanyShortName = c.String(maxLength: 100),
                        CompanyAddress = c.String(maxLength: 500),
                        CompanyEmail = c.String(maxLength: 100),
                        CompanySite = c.String(maxLength: 2048),
                        CompanyTel = c.String(maxLength: 100),
                        CompanyFax = c.String(maxLength: 100),
                        PrimaryBusiness = c.String(maxLength: 500),
                        BankCartAccount = c.String(maxLength: 100),
                        BankName = c.String(maxLength: 100),
                        BankCartOwner = c.String(maxLength: 100),
                        Linkman = c.String(maxLength: 100),
                        LinkmanPhone = c.String(maxLength: 100),
                        Memo = c.String(maxLength: 3096),
                        IsPublished = c.Boolean(nullable: false),
                        IsDeleted = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Media",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                        ExtName = c.String(),
                        Path = c.String(),
                        Size = c.Long(nullable: false),
                        CreatedTime = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Article",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Title = c.String(nullable: false, maxLength: 500),
                        Body = c.String(nullable: false),
                        Tags = c.String(maxLength: 1024),
                        Author = c.String(maxLength: 200),
                        Hits = c.Int(nullable: false),
                        StartTime = c.DateTime(),
                        EndTime = c.DateTime(),
                        CreatedTime = c.DateTime(nullable: false),
                        UpdatedTime = c.DateTime(nullable: false),
                        CategoryId = c.Int(),
                        SEOId = c.Int(),
                        IsPublished = c.Boolean(nullable: false),
                        IsDeleted = c.Boolean(nullable: false),
                        SNS_Id = c.String(maxLength: 128),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.ArticleCategory", t => t.CategoryId)
                .ForeignKey("dbo.SEOInfo", t => t.SEOId)
                .ForeignKey("dbo.SNSShareInfoes", t => t.SNS_Id)
                .Index(t => t.CategoryId)
                .Index(t => t.SEOId)
                .Index(t => t.SNS_Id);
            
            CreateTable(
                "dbo.ArticleCategory",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 100),
                        Key = c.String(nullable: false, maxLength: 100),
                        IsPublished = c.Boolean(nullable: false),
                        IsDeleted = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.SNSShareInfoes",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 128),
                        Description = c.String(maxLength: 500),
                        Text = c.String(maxLength: 1024),
                        PopTitle = c.String(maxLength: 500),
                        TopHeight = c.String(maxLength: 500),
                        Comment = c.String(maxLength: 500),
                        PictureUrl = c.String(maxLength: 500),
                        CatchedPic = c.Boolean(nullable: false),
                        WeiboUid = c.String(maxLength: 500),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Users",
                c => new
                    {
                        UserId = c.Int(nullable: false, identity: true),
                        Email = c.String(nullable: false),
                        Name = c.String(nullable: false),
                        UserName = c.String(),
                        PasswordHash = c.String(),
                        DateCreated = c.DateTime(nullable: false),
                        LastLoginTime = c.DateTime(),
                        Activated = c.Boolean(nullable: false),
                        RoleId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.UserId);
            
            CreateTable(
                "dbo.SupplierProducts",
                c => new
                    {
                        Supplier_Id = c.Int(nullable: false),
                        Product_Id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.Supplier_Id, t.Product_Id })
                .ForeignKey("dbo.Suppliers", t => t.Supplier_Id, cascadeDelete: true)
                .ForeignKey("dbo.Product", t => t.Product_Id, cascadeDelete: true)
                .Index(t => t.Supplier_Id)
                .Index(t => t.Product_Id);
            
        }
        
        public override void Down()
        {
            DropIndex("dbo.SupplierProducts", new[] { "Product_Id" });
            DropIndex("dbo.SupplierProducts", new[] { "Supplier_Id" });
            DropIndex("dbo.Article", new[] { "SNS_Id" });
            DropIndex("dbo.Article", new[] { "SEOId" });
            DropIndex("dbo.Article", new[] { "CategoryId" });
            DropIndex("dbo.ProductCategory", new[] { "SEO_Id" });
            DropIndex("dbo.Product", new[] { "SEO_Id" });
            DropIndex("dbo.Product", new[] { "Category_Id" });
            DropForeignKey("dbo.SupplierProducts", "Product_Id", "dbo.Product");
            DropForeignKey("dbo.SupplierProducts", "Supplier_Id", "dbo.Suppliers");
            DropForeignKey("dbo.Article", "SNS_Id", "dbo.SNSShareInfoes");
            DropForeignKey("dbo.Article", "SEOId", "dbo.SEOInfo");
            DropForeignKey("dbo.Article", "CategoryId", "dbo.ArticleCategory");
            DropForeignKey("dbo.ProductCategory", "SEO_Id", "dbo.SEOInfo");
            DropForeignKey("dbo.Product", "SEO_Id", "dbo.SEOInfo");
            DropForeignKey("dbo.Product", "Category_Id", "dbo.ProductCategory");
            DropTable("dbo.SupplierProducts");
            DropTable("dbo.Users");
            DropTable("dbo.SNSShareInfoes");
            DropTable("dbo.ArticleCategory");
            DropTable("dbo.Article");
            DropTable("dbo.Media");
            DropTable("dbo.Suppliers");
            DropTable("dbo.SEOInfo");
            DropTable("dbo.ProductCategory");
            DropTable("dbo.Product");
            DropTable("dbo.SiteConfig");
        }
    }
}
